<template>
  <base-breadcrumb>
    <a-card :bordered="false" style="over-flow:scroll">
      <title-name title="评价表信息"></title-name>
      <a-form-model :model="form" ref="form1" :rules="rules">
        <a-row>
          <a-col :md="9" :sm="9">
            <a-form-model-item
              label="评价表名称"
              :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
              :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }" prop="formName"
            >
              <BaseInput v-model="form.formName"
                         :maxLength="30"
                         :disabled="true"
                         placeholder="请输入"
              />
            </a-form-model-item>
          </a-col>
          <a-col :md="9" :sm="9">
            <a-form-model-item
              label="状态"
              :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
              :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }" prop="enable"
            >
              <a-select v-model="form.enable" :disabled="true">
                <a-select-option value="1">可用</a-select-option>
                <a-select-option value="0">不可用</a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>

      <title-name title="评分项列表"></title-name>
      <div>
        <a-row>
          <a-col :md="24" :sm="19">
            <div class="table-operator">
              <a-row>
                <a-col :md="24" :sm="24">
                  <a-button :loading="loading" type="primary" :disabled="pageType=='view'" @click="goAdd()">
                    新增评分项
                  </a-button>
                  <a-button :disabled="pageType=='view'|| selectedRowKeys.length===0" @click="goDel()">删除</a-button>
                </a-col>
              </a-row>
            </div>
            <div class="pub-table-select-count">
              <a-icon type="info-circle" theme="twoTone" />
              <span> 总计<span class="totalNum">{{ total.itemNum }}项</span> </span> |
              <span> 可用总计 <span class="totalNum">{{ total.enableNum }}</span> 项  </span> |
              <span> 可用总分数 <span class="totalNum">{{ total.totalScore }}</span> 分  </span>
            </div>
            <a-table
              :loading="loading"
              bordered
              :pagination="false"
              :scroll="{ x: 1600}"
              :columns="columns"
              :data-source="tableData"
              :row-selection="rowSelection"
            >
              <span slot="serial" slot-scope="text, record, index">{{ index + 1 }}</span>
              <template v-if="pageType !=='view' " slot="action" slot-scope="text, record">
                <a @click="handleSub(record,'view')">查看</a>
                <a-divider type="vertical" />
                <a @click="handleEdit(record)">编辑</a>
              </template>
            </a-table>
          </a-col>
        </a-row>
      </div>
    </a-card>


    <div style="float:right;" class="page-btn-right-top">
      <a-button type="primary" :disabled="pageType=='view'" @click="submit">提交
      </a-button>
      <a-button type="primary" class="ml12" @click="goBack">关闭</a-button>
    </div>

    <a-modal
      :title="titles"
      v-model="visible"
      width="800px"
      destroyOnClose
    >
      <template slot="footer">
        <a-button key="back" @click="handleCancel">取消</a-button>
        <a-button key="submit" :loading="configloadings" type="primary" @click="handleOk">确定</a-button>
      </template>

      <DynamicForm ref="dynamicForm"
                   :loading="loadingState.loadingEdit"
                   :fullRowTypes="['TEXT_AREA']"
                   v-bind="$attrs"
                   :formData="formDatas"
                   :maxLength="true"
                   :defaultData="defaultData"
      />
    </a-modal>
  </base-breadcrumb>
</template>

<script>
import { STable, Ellipsis } from '@/components'
import {
  getScoreList,
  addScoreList,
  editScoreList,
  getEvaluateListTotal,
  deleteScoreList,
  editEvaluateList,
  getEvaluateTotals,
  getEvaluateOne
} from '@/api/evaluate'
import { getProjectJobsList } from '@/api/project/projectsJobs'
import { getProjectIdFromOrg } from '@/api/index'
import cloneDeep from 'lodash.clonedeep'

import { getHeaders, getContent, getTypeLabel } from '@/api/commons'
import DynamicForm from '@/components/DynamicForm/index.js'

export default {
  components: {
    STable,
    DynamicForm
  },
  data() {

    return {
      configloadings: false,
      titles: '', // 评分项表头
      rules: {
        formName: [{ required: true, message: '请输入评价表名称', trigger: 'blur' }],
        enable: [{ required: true, message: '请选择状态', trigger: 'change' }]
      },
      loadingState: {
        loadingEdit: false
      },
      efficiencys: [],
      resourcesEvaluation: [],
      loading: false,
      evaluationName2: ['专业分包方案讲评评分表'],
      // 查询参数
      evaluationName: ['专业分包方案讲评评分表','分包商月度考核评价表', '分包商季度考核评价表', '设计资源考核评价表', '设计策划编制评审表', '设计效能考核表', '专业工程施工方案讲解评价表', '施工组织设计(方案)编制评价表', '回填土专项治理查评分表', '工程渗漏专项治理查评分表', '混凝土观感专项治理查评分表'],
      queryParam: {},
      tableData: [],
      formDatas: [],
      defaultData: {},
      data: {},
      deparments: [], // 考核部门

      addForm: {},
      // 加载数据方法 必须为 Promise 对象
      selectedRowKeys: [],
      selectedRows: [],
      columns: [],
      id: '',
      name: '',
      type: '',
      status: '',
      pageType: '',
      jobsList: [],

      classifications: [],  // 考核分类
      types: [],  // 考核类型

      list: [
        { id: 1, name: '分包商月度考核评价表' },
        { id: 2, name: '分包商季度考核评价表' },
        { id: 3, name: '设计策划编制评审表' },
        { id: 4, name: '设计效能考评表' },
        { id: 5, name: '设计资源考核评价表' },
        { id: 6, name: '专业工程施工方案讲解评价表' },
        { id: 7, name: '施工组织设计（方案）编制评价表' },
        { id: 8, name: '回填土专项治理查评分表' },
        { id: 9, name: '工程渗漏专项治理查评分表' },
        { id: 10, name: '混凝土观感专项治理查评分表' }
      ],
      form: {
        id: '',
        formName: '',
        enable: 1
      },
      total: {},
      visible: false,
      isMultiple: false,  // 表单是否多选
      viewScoreForm: false //查看评分项
    }
  },
  computed: {
    rowSelection() {
      return {
        selectedRowKeys: this.selectedRowKeys,
        selectedRows: this.selectedRows,   // 当前行所有数据
        onChange: this.onSelectChange
      }
    },
    disabled() {
      return this.id == '793743653905502208' || this.id == '793743600440709120' || this.id == '793743540508299264'
    }
  },
  created: async function() {
    await this.getProjectIdFromOrg()
    await this.getProjectJobsList()
    this.id = this.$route.query.id
    this.form.formName = this.$route.query.name
    if (this.form.formName == '分包商月度考核评价表') {
      this.type = 1
    } else if (this.form.formName == '分包商季度考核评价表') {
      this.type = 2
    } else if (this.form.formName == '设计策划编制评审表') {
      this.type = 3
    } else if (this.form.formName == '设计效能考核表') {
      this.type = 4
    } else if (this.form.formName == '设计资源考核评价表') {
      this.type = 5
    } else if (this.form.formName == '专业工程施工方案讲解评价表') {
      this.type = 6
    } else if (this.form.formName == '施工组织设计(方案)编制评价表') {
      this.type = 7
    } else if (this.form.formName == '回填土专项治理查评分表') {
      this.type = 8
    } else if (this.form.formName == '工程渗漏专项治理查评分表') {
      this.type = 9
    } else if (this.form.formName == '混凝土观感专项治理查评分表') {
      this.type = 10
    } else if (this.form.formName == '专业分包方案讲评评分表') {
      this.type = 11
    }
    let status = this.$route.query.status

    this.form.enable = status === '可用' ? '1' : '0'
    this.pageType = this.$route.query.type
    this.getHeaders()
    this.getEvaluateTotals()
    await this.getContent()
    await this.getTypeLabel()
    console.log(this.formDatas,'')
  },
  methods: {
    // 评分项统计
    getEvaluateTotals() {
      getEvaluateTotals({ formId: this.id }).then(res => {
        if (res.code == 200) {
          this.total = res.data
        }
      })
    },
    // 获取分公司下的部门
    async getProjectIdFromOrg() {
      let res = await getProjectIdFromOrg({ parentCodes: ['BC'], pageNum: 1, pageSize: 50, baseOrgType: 1 }).catch(() => {
        this.loading = false
      })
      this.deparments = res.data.list || []
      this.formDatas.forEach(item => {
        if (item.code === '9') {
          item.selectList = this.deparments
        }
      })
    },

    async getProjectJobsList(callack) {
      let res = await getProjectJobsList({ typeStatusCode: 1, pageNo: 1, pageSize: 1000 }).catch(() => {
        this.loading = false
      })
      if (res.code === 200 || res.data.code === 200) {
        this.jobsList = res.data || []
        this.formDatas.forEach(item => {
          if (item.code === '5') {
            item.selectList = this.jobsList
          }
        })
        callack && callack()
      }
    },

    async getTypeLabel() {
      this.loading = true
      // 考核分类
      //设计效能考核评价表
      if (this.type == 4) {
        let res = await getTypeLabel({ type: 5 }).catch(() => {
          this.loading = false
        })
        if (res.code === 200 || res.data.code === 200) {
          this.efficiencys = res.data
          this.formDatas.forEach(item => {
            if (item.code === '2') {
              item.selectList = this.efficiencys
            }
          })
        }
      }

      // 设计资源考核评价表
      if (this.type == 5) {
        let res = await getTypeLabel({ type: 6 }).catch(() => {
          this.loading = false
        })
        if (res.code === 200 || res.data.code === 200) {
          this.resourcesEvaluation = res.data
          this.formDatas.forEach(item => {
            if (item.code === '2') {
              item.selectList = this.resourcesEvaluation
            }
          })
        }
      }
      this.loading = false
    },
    getHeaders() {
      console.log('this.id', this.id)
      if (this.id == '793743653905502208' || this.id == '793743600440709120' || this.id == '793743540508299264') {
        this.specialGetHeaders()
      } else {
        getHeaders({ formId: this.id }).then(res => {
          this.formDatas = cloneDeep(res.data)
          this.formDatas.forEach((obj, i) => {

            if (obj.code == '2' && obj.inputType == 'SELECT' && this.type == 4) {
              obj.selectList = this.efficiencys
              obj.selectOptions = { labelName: 'name', valueName: 'id' }
            }

            if (obj.code == '2' && obj.inputType == 'SELECT' && this.type == 5) {
              obj.selectList = this.resourcesEvaluation
              obj.selectOptions = { labelName: 'name', valueName: 'id' }
            }

            if (obj.code == '4') {
              this.formDatas = this.formDatas.map(item => {
                item.$attrs = item.$attrs ? {
                  ...item.$attrs,
                  isInt: true
                } : {
                  isInt: true
                }
                return item
              })
            }

            if (obj.code == '3') {
              obj.$listeners = {
                change: (val) => {
                  this.formDatas = this.formDatas.map(item => {
                    if (item.code === '4') {
                      if (val === '否决项') {
                        item.hidden = true
                      } else {
                        item.hidden = false
                      }
                    }
                    return item
                  })
                }
              }
              obj.selectList = [{ label: '否决项', value: '否决项' }, { label: '评分项', value: '评分项' }]
            }

            if (obj.code == '5') {
              obj.inputType = 'MULTIPLE_SELECT'
              obj.selectList = this.jobsList
              obj.selectOptions = { labelName: 'jobName', valueName: 'postId' }
            }

            if (obj.code == '9') {
              obj.selectList = this.deparments
              obj.selectOptions = { labelName: 'name', valueName: 'id' }
            }

            if (obj.code == '8' || obj.code == '7') {
              obj.selectList = [{ label: '不可用', value: '不可用' }, { label: '可用', value: '可用' }]
            }
          })
          res.data && res.data.forEach(item => item.ellipsis = true)
          if(this.type === 11) {
            const labelEmue = ['考核评分', '状态']
            const arr = []
            const formDatas = []
            this.formDatas.forEach(item=>{
              if(item.title === '考核名称') {
                item.title = '考核评分项'
                formDatas.push(item)
              }
              else if(item.title === '主要检查内容') {
                item.title = '评分关注重点'
                formDatas.splice(2, 0, item)
              }
              else if(labelEmue.includes(item.title)) {
                formDatas.push(item)
              }
            })
            this.formDatas =  formDatas
            res.data.forEach(item => {
              if(item.title === '考核名称') {
                item.title = '考核评分项'
                arr.push(item)
              }
              else if(item.title === '主要检查内容') {
                item.title = '评分关注重点'
                arr.splice(1, 0, item)
              }
             else if(labelEmue.includes(item.title)) {
                arr.push(item)
              }
            })
            this.columns = arr;
          } else {
            this.columns = res.data
          }
          let obj = {
            'dataIndex': 'serial',
            'formId': null,
            'title': '序号',
            'code': '0',
            'sort': 0,
            'width': 65,
            'inputType': null,
            scopedSlots: { customRender: 'serial' }
          }
          this.columns.unshift(obj)

          this.columns.push({
            'dataIndex': 'action',
            'formId': null,
            'title': '操作',
            'code': '0',
            'sort': 0,
            'inputType': null,
            'fixed': 'right',
            'align': 'center',
            width: 130,
            scopedSlots: { customRender: 'action' }
          })
        })
      }
    },
    specialGetHeaders() {
      getHeaders({ formId: this.id }).then(res => {
        let resIndex = res.data.findIndex(v => v.code == '2' && v.title == '考核分类')
        res.data.splice(resIndex, 1)

        this.formDatas = cloneDeep(res.data)
        this.formDatas.forEach((obj, i) => {

          if (obj.code == '2' && obj.inputType == 'SELECT' && this.type == 4) {
            obj.selectList = this.efficiencys
            obj.selectOptions = { labelName: 'name', valueName: 'id' }
          }

          if (obj.code == '2' && obj.inputType == 'SELECT' && this.type == 5) {
            obj.selectList = this.resourcesEvaluation
            obj.selectOptions = { labelName: 'name', valueName: 'id' }
          }

          if (obj.code == '4') {
            this.formDatas = this.formDatas.map(item => {
              item.$attrs = item.$attrs ? {
                ...item.$attrs,
                isInt: true
              } : {
                isInt: true
              }
              return item
            })
          }

          if (obj.code == '3') {
            obj.$listeners = {
              change: (val) => {
                this.formDatas = this.formDatas.map(item => {
                  if (item.code === '4' || item.code === '10') {
                    if (val === '否决项') {
                      item.hidden = true
                    } else {
                      item.hidden = false
                    }
                  }
                  if (item.code === '6') {
                    if (val === '否决项') {
                      item.title = '主要检查内容'
                    } else {
                      item.title = '扣分标准'
                    }

                    item.$attrs = {
                      rules: {
                        required: true,
                        message: `请输入${item.title}!`
                      }
                    }
                  }
                  return item
                })
              }
            }
            obj.selectList = [{ label: '否决项', value: '否决项' }, { label: '评分项', value: '评分项' }]
          }

          if (obj.code == '6') {
            obj.inputType = 'TEXT_AREA'
            // obj.inputType = 'MULTIPLE_SELECT'
            // obj.selectList = this.jobsList
            // obj.selectOptions = { labelName: 'jobName', valueName: 'postId' }
          }

          if (obj.code == '9') {
            obj.selectList = this.deparments
            obj.selectOptions = { labelName: 'name', valueName: 'id' }
          }

          if (obj.code == '8') {
            obj.selectList = [{ label: '不可用', value: '不可用' }, { label: '可用', value: '可用' }]
          }
        })
        res.data && res.data.forEach(item => item.ellipsis = true)
        this.columns = res.data

        let obj = {
          'dataIndex': 'serial',
          'formId': null,
          'title': '序号',
          'code': '0',
          'sort': 0,
          'inputType': null,
          scopedSlots: { customRender: 'serial' }
        }
        this.columns.unshift(obj)

        this.columns.push({
          'dataIndex': 'action',
          'formId': null,
          'title': '操作',
          'code': '0',
          'sort': 0,
          'inputType': null,
          'fixed': 'right',
          'align': 'center',
          width: 130,
          scopedSlots: { customRender: 'action' }
        })
      })
    },
    submit() {   // 提交
      this.$refs.form1.validate((err, value) => {
        if (err) {
          this.form.id = this.id
          //克隆一遍this.form。不然下拉框会报错
          let data = this.$clone(this.form)
          data.enable = data.enable === '1'
          editEvaluateList(data).then(res => {
            if (res.code === 200) {
              this.$message.success('提交成功')
              this.$router.push({ path: '/project/evalution/list' })
            }
          })
        }
      })

    },
    goBack() {   // 关闭
      this.$multiTab.close(this.$route.fullpath)
    },
    handleOk() {
      if (this.id == '793743653905502208' || this.id == '793743600440709120' || this.id == '793743540508299264') {
        return this.specialHandleOk()
      }
      if (this.configloadings) {
        return
      }
      this.$refs.dynamicForm.$refs.form.validate((err, value) => {
        if (err) {
          let form = this.$refs.dynamicForm.getFormInfo()

          //找到code为5的数据，数组组装成字符串
          this.formDatas.map(v => {
            if (v.code === '5') {
              for (let formElement in form) {
                if (formElement === v.dataIndex) {
                  let item = form[formElement]
                  // if (typeof item === 'object') {
                  form[formElement] = item.length ? item.join(',') : ''
                  // }
                }
              }
            }
          })
          this.$console(form)

          // return

          let arr = []
          for (let k in form) {
            if (form.hasOwnProperty(k)) {
              if (k != 'id') {
                arr.push({
                  headerItemId: k,
                  value: form[k],
                  veto: true
                })
              }

            }
          }
          this.addForm.formId = this.id
          this.addForm.itemChild = arr

          if (!this.viewScoreForm) {
            if (this.defaultData.id) {
              this.addForm.id = this.defaultData.id
              this.configloadings = true
              editScoreList(this.addForm).then((res) => {
                this.configloadings = false
                if (res.code == '200') {
                  this.$message.success('编辑成功')
                  this.visible = false
                  this.getContent()
                  this.getEvaluateTotals()
                }
              }).catch(() => {
                this.configloadings = false
              })
            } else {
              if (this.addForm.itemChild.length == 0) {
                this.$message.error('请先录入评分项信息！')
                return
              }
              this.configloadings = true
              addScoreList(this.addForm).then((res) => {
                this.configloadings = false
                if (res.code == '200') {
                  this.$message.success('新增成功')
                  this.getContent()
                  this.getEvaluateTotals()
                  this.visible = false
                }
              }).catch(() => {
                this.configloadings = false
              })
            }
          } else {
            this.visible = false
          }
        }

      })
    },
    specialHandleOk() {
      if (this.configloadings) {
        return
      }
      this.$refs.dynamicForm.$refs.form.validate((err, value) => {
        if (err) {
          let form = this.$refs.dynamicForm.getFormInfo()

          this.$console(form)

          // return

          let arr = []
          for (let k in form) {
            if (form.hasOwnProperty(k)) {
              if (k != 'id') {
                arr.push({
                  headerItemId: k,
                  value: form[k],
                  veto: true
                })
              }

            }
          }
          this.addForm.formId = this.id
          this.addForm.itemChild = arr

          if (!this.viewScoreForm) {
            if (this.defaultData.id) {
              this.addForm.id = this.defaultData.id
              this.configloadings = true
              editScoreList(this.addForm).then((res) => {
                this.configloadings = false
                if (res.code == '200') {
                  this.$message.success('编辑成功')
                  this.visible = false
                  this.getContent()
                  this.getEvaluateTotals()
                }
              }).catch(() => {
                this.configloadings = false
              })
            } else {
              if (this.addForm.itemChild.length == 0) {
                this.$message.error('请先录入评分项信息！')
                return
              }
              this.configloadings = true
              addScoreList(this.addForm).then((res) => {
                this.configloadings = false
                if (res.code == '200') {
                  this.$message.success('新增成功')
                  this.getContent()
                  this.getEvaluateTotals()
                  this.visible = false
                }
              }).catch(() => {
                this.configloadings = false
              })
            }
          } else {
            this.visible = false
          }
        }

      })
    },
    async getContent() {
      this.loading = true
      let res = await getContent({ formId: this.id }).catch(() => {
        this.loading = false
      })
      this.tableData = res.data
      this.loading = false
    },
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    },
    search() {
      this.$refs.table.refresh(true)
    },
    goAdd() {
      this.titles = '新增评分项'
      this.viewScoreForm = false
      if (this.loading) return
      this.loading = true
      this.getProjectJobsList(() => {
        this.defaultData = {}
        this.loading = false
        this.formDatas = this.formDatas.map(item => {
          item.$attrs = item.$attrs ? {
            ...item.$attrs,
            disabled: false,
            rules: {
              required: true,
              message: `请${item.inputType === 'INPUT' || item.inputType === 'TEXT_AREA' ? '输入' : '选择'}${item.title}!`
            }
          } : {
            disabled: false
          }
          // 考核评分设置为数字，并且只能是整数
          // if (item.title && item.title === '考核评分') {
          //     // item.inputType = 'NUMBER'
          //     item.$attrs.rules = {validator:validatorInt, required: true}
          // }
          return {
            ...item
          }
        })
        this.visible = true
      })
    },
    goDel() {
      let _this = this

      if (_this.selectedRowKeys.length == 0) {
        _this.$message.warning('请先选择需要删除的评分项！')
        return
      }
      _this.$confirm({
        okText: '删除',
        okType: 'danger',
        cancelText: '取消',
        title: '删除当前选择的评分项?',
        onOk() {
          let data = []
          _this.selectedRows.forEach(item => {
            data.push(item.id)
          })
          return new Promise((resolve, rej) => {
            deleteScoreList({ ids: data }).then((res) => {
              resolve()
              if (res.data.code == '200') {
                _this.getContent()
                _this.getEvaluateTotals()
                _this.$message.success('删除成功')
                _this.selectedRowKeys = []
                _this.selectedRows = []
                _this.$refs.table.refresh(true)
              }
            }).catch(() => rej)
          })
        },
        onCancel() {
        }
      })

    },
    handleSub(record, type) {
      if (this.id == '793743653905502208' || this.id == '793743600440709120' || this.id == '793743540508299264') {
        return this.specialHandleSub(record, type)
      }
      this.defaultData = record
      this.visible = true
      this.titles = '查看评分项'
      this.viewScoreForm = true
      this.formDatas = this.formDatas.map(item => {
        item.$attrs = item.$attrs ? {
          ...item.$attrs,
          disabled: true
        } : {
          disabled: true
        }
        return {
          ...item
        }
      })

      //找到code为5的数据，切割成数组
      this.formDatas.map(v => {
        if (v.code === '5') {
          for (let key in this.defaultData) {
            if (key === v.dataIndex) {
              if (this.defaultData[key]) {
                this.defaultData[key] = this.defaultData[key].split('/')
              } else {
                this.defaultData[key] = []
              }
            }
          }
        }
      })
    },
    specialHandleSub(record, type) {
      this.defaultData = record
      this.visible = true
      this.titles = '查看评分项'
      this.viewScoreForm = true
      this.formDatas = this.formDatas.map(item => {
        item.$attrs = item.$attrs ? {
          ...item.$attrs,
          disabled: true
        } : {
          disabled: true
        }
        return {
          ...item
        }
      })
    },
    handleEdit(record) {
      if (this.id == '793743653905502208' || this.id == '793743600440709120' || this.id == '793743540508299264') {
        return this.specialHandleEdit(record)
      }
      let that = this
      that.titles = '编辑评分项'
      that.getProjectJobsList(() => {
        that.loading = false
        that.visible = true
        that.viewScoreForm = false
      })
      that.loadingState.loadingEdit = true

      getEvaluateOne({ id: record.id }).then((res) => {
        that.loadingState.loadingEdit = false
        that.defaultData = { ...res.data }
        that.formDatas = that.formDatas.map(item => {
          item.$attrs = item.$attrs ? {
            ...item.$attrs,
            disabled: false
          } : {
            disabled: false
          }
          return {
            ...item
          }
        })
        that.formDatas.map(v => {
          if (v.code === '5') {
            for (let key in that.defaultData) {
              if (key === v.dataIndex) {
                if (that.defaultData[key]) {
                  that.defaultData[key] = that.defaultData[key].split(',')
                } else {
                  that.defaultData[key] = []
                }
              }
            }
          }
        })
        const typeData = that.formDatas.find(item => item.code === '3') // 考核类型
        const scoreData = that.formDatas.find(item => item.code === '4') // 考核评分
        if (that.defaultData[typeData.dataIndex] === '否决项') { // 根据考核类型的值，如果是“否决项”，则隐藏考核评分；反之，则显示
          scoreData.hidden = true
        } else {
          scoreData.hidden = false
        }
      }).catch(() => {
        that.loadingState.loadingEdit = false
      })
    },
    specialHandleEdit(record) {
      let that = this
      that.titles = '编辑评分项'
      that.getProjectJobsList(() => {
        that.loading = false
        that.visible = true
        that.viewScoreForm = false
      })
      that.loadingState.loadingEdit = true

      getEvaluateOne({ id: record.id }).then((res) => {
        that.loadingState.loadingEdit = false
        that.defaultData = { ...res.data }
        that.formDatas = that.formDatas.map(item => {
          item.$attrs = item.$attrs ? {
            ...item.$attrs,
            disabled: false
          } : {
            disabled: false
          }
          return {
            ...item
          }
        })
        this.formDatas = this.formDatas.map(item => {
          item.$attrs = item.$attrs ? {
            ...item.$attrs,
            disabled: false,
            rules: {
              required: true,
              message: `请${item.inputType === 'INPUT' || item.inputType === 'TEXT_AREA' ? '输入' : '选择'}${item.title}!`
            }
          } : {
            disabled: false
          }
          // 考核评分设置为数字，并且只能是整数
          // if (item.title && item.title === '考核评分') {
          //     // item.inputType = 'NUMBER'
          //     item.$attrs.rules = {validator:validatorInt, required: true}
          // }
          return {
            ...item
          }
        })
        const typeData = that.formDatas.find(item => item.code === '3') // 考核类型
        const scoreData = that.formDatas.find(item => item.code === '4') // 考核评分
        if (that.defaultData[typeData.dataIndex] === '否决项') { // 根据考核类型的值，如果是“否决项”，则隐藏考核评分；反之，则显示
          scoreData.hidden = true
        } else {
          scoreData.hidden = false
        }
      }).catch(() => {
        that.loadingState.loadingEdit = false
      })
    },
    handleCancel() {
      this.visible = false
    }
  }
}
</script>

<style scoped>
.input {
  width: 100%
}
</style>
